#include "View.h"
#include "Math.h"
namespace sl
{
	View::View()
	{
		// create the camera and set the default property
		m_rCamera = new Camera();
		m_rCamera->SetView( this );
		m_rCamera->SetViewport( new Viewport() );
		m_rCamera->SetProjectionMatrixAsProjective( 45.0f, 1.3, 1.0, 1000 );
		m_rCamera->SetViewMatrixAsLookAt(sl::Vector3( 0.0f, 0.0f, -10.0f),sl::Vector3(0.0f,0.0f,0.0f),
			sl::Vector3(0.0f, 1.0f, 0.0 ));
	}

	View::~View(void)
	{
	}

	void View::setViewport( u32 x, u32 y, u32 width, u32 height )
	{
		m_rCamera->SetViewport( x, y, width, height );
	}


	void View::addSlave( sl::Camera * camera, sl::Matrix4 & view, sl::Matrix4 & project )
	{
		m_sSlaves.push_back( Slave( camera, view, project ));
	}

	void View::removeSlave( u32 iPos )
	{
		if ( iPos >= m_sSlaves.size() )
			return;
		m_sSlaves.erase( m_sSlaves.begin() + iPos );
	}

	u32 View::getNumSlave()
	{
		return m_sSlaves.size();
	}

	View::Slave View::getSlave( u32 iPos )
	{
		return m_sSlaves[iPos];
	}


	void View::setProjectMatrixAsProjective( double fov, double aspectRatio, double zNear, double zFar )
	{
		m_rCamera->SetProjectionMatrixAsProjective( fov, aspectRatio, zNear, zFar );
	}

	void View::setViewMatrixAsLookAt( Vector3 & eye, Vector3 & center, Vector3 & up )
	{
		m_rCamera->SetViewMatrixAsLookAt( eye, center, up );
	}

	void View::updateSlaves()
	{
		// inherite master camera property
	}
}
